<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图书管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
    <style>
        body {
            background: #f8f9fa;
            background-image: 
                radial-gradient(circle at 20% 50%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 40% 80%, rgba(120, 219, 226, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 0% 100%, rgba(120, 119, 198, 0.2) 0%, transparent 50%),
                radial-gradient(circle at 80% 100%, rgba(255, 198, 119, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 0% 0%, rgba(198, 255, 119, 0.2) 0%, transparent 50%);
            background-size: 400px 400px, 300px 300px, 350px 350px, 250px 250px, 450px 450px, 200px 200px;
            background-position: 0 0, 100px 100px, 200px 50px, 300px 200px, 50px 300px, 400px 0;
            animation: floatPattern 20s ease-in-out infinite;
            min-height: 100vh;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        @keyframes floatPattern {
            0%, 100% {
                background-position: 0 0, 100px 100px, 200px 50px, 300px 200px, 50px 300px, 400px 0;
            }
            50% {
                background-position: 50px 20px, 150px 80px, 250px 30px, 350px 180px, 100px 280px, 450px 20px;
            }
        }
        .main-container {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            margin: 20px auto;
            max-width: 1200px;
        }
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            border-radius: 20px 20px 0 0;
            text-align: center;
        }
        .header h1 {
            margin: 0;
            font-weight: 300;
            font-size: 2.5rem;
        }
        .header p {
            margin: 10px 0 0 0;
            opacity: 0.9;
        }
        .content-section {
            padding: 30px;
        }
        .card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
        }
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            border-radius: 10px;
            padding: 10px 20px;
            font-weight: 500;
            transition: all 0.3s ease;
        }
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        .btn-success {
            background: linear-gradient(135deg, #56ab2f 0%, #a8e6cf 100%);
            border: none;
            border-radius: 10px;
        }
        .btn-warning {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            border: none;
            border-radius: 10px;
        }
        .btn-danger {
            background: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%);
            border: none;
            border-radius: 10px;
        }
        .form-control {
            border-radius: 10px;
            border: 2px solid #e9ecef;
            transition: border-color 0.3s ease;
        }
        .form-control:focus {
            border-color: #667eea;
            box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
        }
        .table {
            border-radius: 15px;
            overflow: hidden;
        }
        .table thead th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            font-weight: 500;
        }
        .table tbody tr {
            transition: background-color 0.3s ease;
        }
        .table tbody tr:hover {
            background-color: rgba(102, 126, 234, 0.1);
        }
        .status-indicator {
            display: inline-block;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            margin-right: 8px;
        }
        .status-success {
            background-color: #28a745;
        }
        .status-error {
            background-color: #dc3545;
        }
        .loading {
            display: none;
            text-align: center;
            padding: 20px;
        }
        .modal-content {
            border-radius: 15px;
            border: none;
        }
        .modal-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 15px 15px 0 0;
        }
        .pagination {
            justify-content: center;
        }
        .page-link {
            border-radius: 10px;
            margin: 0 2px;
            border: none;
            color: #667eea;
        }
        .page-item.active .page-link {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
        }
        .search-box {
            background: white;
            border-radius: 15px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="main-container">
            <!-- 头部 -->
            <div class="header">
                <div class="d-flex justify-content-between align-items-start">
                    <div>
                        <h1><i class="bi bi-book"></i> 图书管理系统</h1>
                        <p>现代化的图书信息管理平台</p>
                        <div class="mt-3">
                            <span class="status-indicator status-success"></span>
                            <span id="connectionStatus">系统状态检查中...</span>
                        </div>
                    </div>
                    <div class="text-end" id="userInfo" style="display: none;">
                        <div class="mb-2">
                            <i class="bi bi-person-circle"></i>
                            <span id="currentUserName">用户</span>
                            <span class="badge bg-light text-dark ms-2" id="currentUserRole">USER</span>
                        </div>
                        <button class="btn btn-outline-light btn-sm" onclick="logout()">
                            <i class="bi bi-box-arrow-right"></i> 退出登录
                        </button>
                    </div>
                </div>
            </div>

            <!-- 主要内容 -->
            <div class="content-section">
                <!-- 搜索和操作区域 -->
                <div class="search-box">
                    <div class="row align-items-end">
                        <div class="col-md-3">
                            <label for="searchName" class="form-label">书名搜索</label>
                            <input type="text" class="form-control" id="searchName" placeholder="输入书名...">
                        </div>
                        <div class="col-md-3">
                            <label for="searchAuthor" class="form-label">作者搜索</label>
                            <input type="text" class="form-control" id="searchAuthor" placeholder="输入作者...">
                        </div>
                        <div class="col-md-2">
                            <label for="pageSize" class="form-label">每页显示</label>
                            <select class="form-control" id="pageSize">
                                <option value="5">5条</option>
                                <option value="10" selected>10条</option>
                                <option value="20">20条</option>
                                <option value="50">50条</option>
                            </select>
                        </div>
                        <div class="col-md-4">
                            <div class="d-flex gap-2">
                                <button class="btn btn-primary" onclick="searchBooks()">
                                    <i class="bi bi-search"></i> 搜索
                                </button>
                                <button class="btn btn-success" onclick="showAddModal()">
                                    <i class="bi bi-plus-circle"></i> 添加图书
                                </button>
                                <button class="btn btn-warning" onclick="refreshData()">
                                    <i class="bi bi-arrow-clockwise"></i> 刷新
                                </button>
                                <button class="btn btn-info" onclick="checkSystemStatus()">
                                    <i class="bi bi-gear"></i> 系统诊断
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 加载指示器 -->
                <div class="loading" id="loading">
                    <div class="spinner-border text-primary" role="status">
                        <span class="visually-hidden">加载中...</span>
                    </div>
                    <p class="mt-2">数据加载中，请稍候...</p>
                </div>

                <!-- 图书列表 -->
                <div class="card">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="mb-0"><i class="bi bi-list-ul"></i> 图书列表</h5>
                        <span class="badge bg-primary" id="totalCount">总计: 0 本</span>
                    </div>
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <table class="table table-hover mb-0">
                                <thead>
                                    <tr>
                                        <th width="8%">ID</th>
                                        <th width="25%">书名</th>
                                        <th width="20%">作者</th>
                                        <th width="12%">价格</th>
                                        <th width="15%">创建时间</th>
                                        <th width="20%">操作</th>
                                    </tr>
                                </thead>
                                <tbody id="bookTableBody">
                                    <!-- 数据将通过JavaScript动态加载 -->
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

                <!-- 分页 -->
                <nav aria-label="分页导航" class="mt-4">
                    <ul class="pagination" id="pagination">
                        <!-- 分页按钮将通过JavaScript动态生成 -->
                    </ul>
                </nav>
            </div>
        </div>
    </div>

    <!-- 添加/编辑图书模态框 -->
    <div class="modal fade" id="bookModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modalTitle">
                        <i class="bi bi-book-half"></i> 添加图书
                    </h5>
                    <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <form id="bookForm">
                        <input type="hidden" id="bookId">
                        <div class="mb-3">
                            <label for="bookName" class="form-label">书名 *</label>
                            <input type="text" class="form-control" id="bookName" required>
                        </div>
                        <div class="mb-3">
                            <label for="bookAuthor" class="form-label">作者 *</label>
                            <input type="text" class="form-control" id="bookAuthor" required>
                        </div>
                        <div class="mb-3">
                            <label for="bookPrice" class="form-label">价格 *</label>
                            <div class="input-group">
                                <span class="input-group-text">¥</span>
                                <input type="number" class="form-control" id="bookPrice" step="0.01" min="0" required>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
                        <i class="bi bi-x-circle"></i> 取消
                    </button>
                    <button type="button" class="btn btn-primary" onclick="saveBook()">
                        <i class="bi bi-check-circle"></i> 保存
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- 系统状态模态框 -->
    <div class="modal fade" id="statusModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">
                        <i class="bi bi-gear"></i> 系统诊断报告
                    </h5>
                    <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <div id="statusContent">
                        <div class="text-center">
                            <div class="spinner-border text-primary" role="status">
                                <span class="visually-hidden">检查中...</span>
                            </div>
                            <p class="mt-2">正在进行系统诊断...</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="app.js"></script>
</body>
</html>